<?
require("config.php");

function getName($id) {
	$sql="select name,parent from  pro_category  where id=$id";
	$r=myQuery($sql);
	if ($id) return getName($r[0][1]).'&gt;'.$r[0][0];
		else return'';
}


$label = "Inventory Stock / Transactions  ";

$close=0;

require($rela_path . "inc/header1.php");
?>
<table width="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td valign="top">
	<a href="<?=$PHP_SELF?>">[ ALL Products ]</a><br>	<form action="" method="get" name="catform" id="catform">
	  Select Category <?

$tb = "pro_category";

$Query = "select name,id,cname from $tb WHERE level=0 order by id";
$r = myQuery($Query);


$Query = "select name, parent,id,cname from $tb WHERE level=1 order by id";
$r1 = myQuery($Query);

$Query = "select name, parent,id,cname from $tb WHERE level=2 order by id";
$r2 = myQuery($Query);

$sourceData = array();
$sourceLabel = array();

for ($i=0;$i<count($r);$i++){

	array_push($sourceData,$r[$i][1]);
	array_push($sourceLabel,$r[$i][0].' '.$r[$i][2]);

	for ($n=0;$n<count($r1);$n++){

		if ($r[$i][1]==$r1[$n][1]){

			array_push($sourceData,$r1[$n][2]);
			array_push($sourceLabel,"-&nbsp;&nbsp;&nbsp;" . $r1[$n][0].' '.$r1[$n][3] );

			for ($m=0;$m<count($r2);$m++){

			if ($r1[$n][2]==$r2[$m][1]){

				array_push($sourceData,$r2[$m][2]);
				array_push($sourceLabel,"---&nbsp;&nbsp;&nbsp;" . $r2[$m][0].' '.$r2[$m][3] );

			}
			}

		}
	}
}

FFPSelectBox('cat',$cat,$sourceData,$sourceLabel);

?>
      <input type="submit" name="Submit" value="Submit">
        </form></td>
    </tr>
  <tr>
    <td valign="top">
<?
	

$table="pro_basic";
$cat=$_GET['cat'];

if ($cat) {
	$pos=getName($cat);
}

if ($cat){
	$Query="SELECT 
	id,
	name,
	code,
	stock,
	reorder,
	brand
	FROM $table WHERE 
	category	= '$cat' 
	ORDER BY id DESC";


}
else {
	$Query="SELECT 
	id,
	name,
	code,
	stock,
	reorder,
	brand
	FROM $table 
	ORDER BY id DESC";

}
	$r=myQuery($Query);
?>
<?=$pos?><br>
<br>
[ <a href="export_pro.php?cat=<?=$cat?>">Export to EXCEL</a> ]
<br>
<br>

<table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" class="tb">
  <tr class="tbheader"> 
    <td width="4%"> <div align="center">No.</div></td>
    <td width="48%"> <div align="center">Product Name</div></td>
    <td width="24%"> <div align="center">Product Code</div></td>
    <td width="12%"> <div align="center">Current Stock</div></td>
    <td width="12%"> <div align="center">Current Reorder</div></td>
  </tr>

<?if ($r){
	for ($i=0;$i<count($r);$i++){?>
  <tr class="tbcontent1"> 
    <td width="4%" align="center"><?print($i+1)?></td>
    <td><a href="#" onClick="window.open('../inc/trans.php?search=<?print($r[$i][0])?>&method=product','','width=400 height=400')"><?=$r[$i][1].'<br>'.$r[$i][5]?></a></td>
    <td><?print($r[$i][2])?></td>
    <td> <div align="center"><?print($r[$i][3])?></div></td>
    <td> <div align="center"><?print($r[$i][4])?></div></td>
  </tr>
<?}
}?>


</table></td>
  </tr>
</table>
<?
require($rela_path . "inc/footer1.php");
?>

